from twill import get_browser

def make_browser():
    b = get_browser()
    b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB;rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14")
    b.clear_cookies()
    return b

def gmail_login(b, email, password):
    b.go('http://www.gmail.com')
    f = b.get_form("1")
    f['Email'] = email
    f['Passwd'] = password
    b.clicked(f, f)
    b.submit()

def set_issue_page(b, projectName):
    b.go("http://code.google.com/p/%s/adminTabs" % projectName)
    f = b.get_form("2")
    f['issuespage']= 'youtrack'
    b.clicked(f, f)
    b.submit()

def create_youtrack_page(b, projectName, template):
    b.go("http://code.google.com/p/%s/w/edit" % projectName)
    f = b.get_form("3")
    f['pagename'] = 'youtrack'
    f['content'] = template
    b.clicked(f, f)
    b.submit("33")
